const jwt = require('koa-jwt');
const Router = require('koa-router');
const router = new Router({ prefix: '/questions/:questionId/answers' });
const { secret } = require('../config');

const auth = jwt({ secret });

const {
  find, findById, create, update, delete: del,
  checkAnswerExist, checkAnswerer,
} = require('../controllers/answers');

// 查询某个问题的答案列表(可分页)(可根据关键字查询)
router.get('/', find);
// 新建回答
router.post('/', auth, create);
// 查询指定问题的指定答案
router.get('/:id', checkAnswerExist, findById);

router.patch('/:id', auth, checkAnswerExist, checkAnswerer, update);
router.delete('/:id', auth, checkAnswerExist, checkAnswerer, del);
module.exports = router;